<template>
  <el-form ref="fltForm" label-width="130px" :model="FLT_INFO" size="mini">
    <el-row>
      <el-col :span="24">
        <el-form-item label="派车中心序号：" prop="dptSeq" :rules="rules.dptSeq">
          <el-input :disabled="disabled" maxlength="127" style="width: 100%" v-model="FLT_INFO.dptSeq"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
    <el-col :span="24">
        <el-form-item label="派车中心代码：" prop="dptCode" :rules="rules.dptCode">
          <el-input :disabled="!isAdd" maxlength="20" style="width: 100%" v-model="FLT_INFO.dptCode"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="派车中心名称：" prop="dptName" :rules="rules.dptName">
          <el-input :disabled="disabled" maxlength="37" style="width: 100%" v-model="FLT_INFO.dptName"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="上级机构：" prop="dptFltId" :rules="rules.dptFltId">
          <el-select :disabled="disabled" style="width: 100%" v-model="FLT_INFO.dptFltId">
            <el-option v-for="(item, index) in dptFltIdList" :value="item.uuid" :key="index" :label="item.fltName">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="备注：" prop="remark" :rules="rules.remark">
          <el-input type="textarea" resize="none" :disabled="disabled" maxlength="150" style="width: 100%" rows="10" v-model="FLT_INFO.remark"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row class="el-dialog__footer">
      <el-col :span="24">
        <el-form-item>
          <el-button @click="close">关闭</el-button>
          <el-button v-if="!disabled" @click="save" type="primary">保存</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import {
  getCompanysList
} from '@/request/api';
export default {
  name: 'dialog',
  props: {
    flt_info: {
      type: Object,
      required: true
    },
    disabled: {
      type: Boolean,
      default: false
    },
    showDialog: {
      type: Boolean,
      required: false
    },
    dialogmode: {
      type: String
    }
  },
  data() {
    return {
      FLT_INFO: this.flt_info,

      dptFltIdList: []
    }
  },
  watch: {
    flt_info() {
      this.FLT_INFO = this.flt_info
    }
  },
  computed: {
    // 是否新增操作
    isAdd () {
      return this.dialogmode === this.DIALOG_MODE.ADD
    },
    rules() {
      return {
        dptSeq: [
          { required: true, message: '请输入派车中心序号', trigger: 'blur' },
          // {
          //   pattern: /^[0-9]+$/,
          //   message: '请输入数字',
          //   trigger: ['blur','change']
          // }
        ],
        dptCode: [
          { required: true, message: '请输入派车中心代码', trigger: 'blur' },
          // {
          //   pattern: /^[a-zA-Z0-9 ]+$/,
          //   message: '请输入英文和数字',
          //   trigger: ['blur','change']
          // }
        ],
        dptName: [
          { required: true, message: '请输入派车中心名称', trigger: 'blur' },
          // {
          //   pattern: /^[\u4e00-\u9fa5]+$/,
          //   message: '只能输入中文',
          //   trigger: 'change'
          // }
        ],
        dptFltId: [
          { required: true, message: '请选择上级机构', trigger: 'blur' },
        ]
      }
    }
  },
  mounted () {
    this.$refs.fltForm.clearValidate()
  },
  methods: {
    close() {
      // 关闭时清楚验证信息
      this.$emit('close')
    },
    save() {
      this.$refs['fltForm'].validate(valid => {
        if (valid) {
          this.$emit('save', this.FLT_INFO)
        }
      })
    },
    getCompanys () {
      getCompanysList().then(res => {
        this.dptFltIdList = res.data.FTKJWLHYPT
        // console.log(this.dptFltIdList)
      })
    }
  },
  created() {
    this.getCompanys()
  }
}
</script>

<style lang="scss" scoped></style>
